using BruteForce;
using BruteForce.NewManagers;
using BruteForce.UserInterface.Abstracts;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Bruteforce.UserInterface.UIControls
{
    public delegate void OnClickHandler();

    public class Button : AbstractUIControl
    {
        public Texture2D Image;

        public Button(Texture2D image, string name, Rectangle surroundingRectangle)
            : base(name, surroundingRectangle)
        {
            Image = image;
        }

        public event OnClickHandler OnClick;

        public override void Update()
        {
            if (InputManager.Instance.MouseClicked.IsChangedSince(BFGame.LoopIndex) &&
                InputManager.Instance.IsMouseClickedOn(CurrentUIcontrolRectangle))
            {
                if (OnClick != null) OnClick();
            }
        }

        public override void Draw(GameTime gameTime)
        {
            BFGame.SpriteBatch.Draw(Image,
                                    new Rectangle(CurrentUIcontrolRectangle.X, CurrentUIcontrolRectangle.Y,
                                                  RelativeUIcontrolRectangle.Width, RelativeUIcontrolRectangle.Height),
                                    Color.White);
        }


    }
}